﻿namespace Project2.Application
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;

        public SystemAppService(ISystemService systemService)
        {
            _systemService = systemService;
        }

        /// <summary>
        /// 获取系统描述
        /// </summary>
        /// <returns></returns>
        public string GetDescription()
        {
            return _systemService.GetDescription();
        }

        public async Task<IActionResult> GetToken()
        {
            await Task.CompletedTask;
            var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>()
            {
                { "UserId", "user.Id" },  // 存储Id
                { "Account","user.Account" }, // 存储用户名
            });
            var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 43200);

            return new JsonResult(new { accessToken, refreshToken });
        }

        [Authorize]
        public async Task<IActionResult> GetTset()
        {
            await Task.CompletedTask;
            return new JsonResult(new { message = "Hello World!" });
        }
    }
}